package com.dwxt.cdms.controller;

import com.dwxt.cdms.base.Page;
import com.dwxt.cdms.entity.Customer;
import com.dwxt.cdms.entity.vo.BloodSugarCustom;
import com.dwxt.cdms.service.BloodSugarService;
import com.dwxt.cdms.service.PoctService;
import com.dwxt.common.base.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping("/cdms/sugar")
@RestController
public class BloodSugarController {

    @Autowired
    private BloodSugarService bloodSugarService;

    @Autowired
    private PoctService poctService;


    /**
     * 血糖详情分页
     * @param page
     * @param customer
     * @param isAbnormal
     * @param start
     * @param end
     * @param customerId
     * @return
     */
    @RequestMapping("/selectSugarPage")
    public BaseResult selectSugarPage(Page page, Customer customer, Integer isAbnormal, String start, String end,
                                      String customerId,String partId){
        return bloodSugarService.selectSugarPage(page,customer,isAbnormal,start,end,customerId,partId);
    }

    /**
     * 插入血糖数据
     * @param bloodSugar
     * @return
     */
    @RequestMapping("/insert")
    public BaseResult insert(BloodSugarCustom bloodSugar){
        return bloodSugarService.insert(bloodSugar);
    }

    /**
     * 修改血糖数据
     * @param bloodSugar
     * @return
     */
    @RequestMapping("/update")
    public BaseResult update(BloodSugarCustom bloodSugar){
        return bloodSugarService.update(bloodSugar);
    }

    /**
     * 删除血糖数据
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    public BaseResult delete(String id){
        return bloodSugarService.delete(id);
    }


    /**
     * 按用户分组查询最新血糖数据并分页
     * @param page
     * @param customer
     * @param isAbnormal
     * @param start
     * @param end
     * @param mealtime
     * @return
     */
    @RequestMapping("/selectSugarPageGroup")
    public BaseResult selectSugarPageGroup(Page page, Customer customer, Integer isAbnormal, String start, String end
            ,Integer mealtime){
        return bloodSugarService.selectSugarPageGroup(page,customer,isAbnormal,start,end,mealtime);
    }

    /**
     * @Description: TV获取单个用户血糖曲线数据（poct和血糖仪）
     * @param customerId:
     * @param scope:
     * @return com.dwxt.common.base.BaseResult
     * @author chendq
     * @date 2021/8/19
     */
    @RequestMapping("/selectCustomerSugar")
    public BaseResult selectCustomerSugar(@RequestParam(required = true) Integer customerId,
                                          @RequestParam(required = true,defaultValue = "1")Integer scope,
                                          @RequestParam(required = true,defaultValue = "0")Integer partId){
        return bloodSugarService.selectCustomerSugarFromPoctOrAi(customerId, scope, partId);
    }

    /**
     * 归属角色血糖数据
     * @param map
     * @return
     */
    @PostMapping("/updatePart")
    public BaseResult updatePart(@RequestBody Map map){
        return bloodSugarService.updatePart(map);
    }
}
